const { exec } = require("child_process");

function isProcessRunning(processName) {
  return new Promise((resolve, reject) => {
    try {
      exec(`tasklist | findstr /i "${processName}"`, (error, stdout, stderr) => {
        if (error) {
          reject(error);
          return;
        }
        resolve(stdout.trim() !== "");
      });
    } catch (e) {
      reject(e);
    }
  });
}

isProcessRunning("trae222")
  .then((isRunning) => {
    console.log(`Node process is running: ${isRunning}`);
  })
  .catch((error) => {
    console.error(`Error checking process: ${error.message}`);
  });
